#include "StdAfx.h"
#include "DisplayPanel.h"
#include "MainFrame.h"

#include <MyControls/Constants.h>

My::ToolButtonInfo Modes[] = {
	{ID_DISPLAY_PREVIEW, "DISPLAY_PREVIEW"},
	{ID_DISPLAY_EDITMASK, "DISPLAY_EDITMASK"},
};

DisplayPanel::DisplayPanel(MainFrame & f) : 
	Panel(f), 
	m_Frame(f),
	m_StyleEditor("Display Style Editor"),
	m_Modes(My::ToolBar::HORIZONTAL),
	m_SequenceEvents(static_cast<My::Sequence&>(m_Frame.m_Comp), * this)
{
	m_StyleEditor.ShowInfo(false);
	m_StyleEditor.SetFont(&m_Frame.m_LargeFont);
	Add(&m_StyleEditor);
	m_Modes.SetButtonSize(CSize(18, 16));
	m_Modes.SetButtons(Modes, sizeof(Modes) / sizeof(My::ToolButtonInfo));

	Add(&m_Modes);
	Add(&m_ZoomEdit);
	Add(&m_ZoomIn);
	Add(&m_ZoomOut);
	Add(&m_ZoomSlider);
}

void DisplayPanel::ProcessEvent(My::Event & e)
{
	if (e.Is<My::Sequence::OpenEvent>()) {
		m_StyleEditor.Open(&m_Frame.m_View);
		m_ZoomEdit.SetView(&m_Frame.m_View);
		m_ZoomIn.SetView(&m_Frame.m_View);
		m_ZoomOut.SetView(&m_Frame.m_View);
		m_ZoomSlider.SetView(&m_Frame.m_View);
	} else
	if (e.Is<My::Sequence::CloseEvent>()) {
		m_StyleEditor.Close();
		m_ZoomEdit.SetView(0);
		m_ZoomIn.SetView(0);
		m_ZoomOut.SetView(0);
		m_ZoomSlider.SetView(0);
	} else
		Panel::ProcessEvent(e);
}

CSize DisplayPanel::GetMinClientSize() const
{
	CSize s = m_Modes.GetPreferredSize();
	s.cx += 60 + 100;
	s.cy += 60;
	return s;
}

void DisplayPanel::LayoutControls()
{
	CRect rClient = ClientRect();
	rClient.top += GetHeaderHeight();

	CRect rModes(CPoint(0, 0), m_Modes.GetPreferredSize());
	rModes = My::AlignRect(rClient, rModes, My::ALIGN_HLEFT|My::ALIGN_VBOTTOM);
	m_Modes.SetBounds(rModes);

	CRect r(rModes);
	int w = rClient.Width() - rModes.Width();
	int wZoom = w - 100;
	if (wZoom < 100)
		wZoom = 100;
	int wEdit = w - wZoom;
	r.left = rModes.right;
	r.right = r.left + wEdit;
	m_ZoomEdit.SetBounds(r);

	r.left = r.right;
	r.right = r.left + 25;
	m_ZoomOut.SetBounds(r);
	r.left = r.right;
	r.right = r.left + wZoom - 50;
	m_ZoomSlider.SetBounds(r);
	r.left = r.right;
	r.right = r.left + 25;
	m_ZoomIn.SetBounds(r);

	rClient.bottom = rModes.top;
	m_StyleEditor.SetBounds(rClient);
}
